Hi,
I am using this page: admin/build/services/browse/node.save
This works:
{"type":"type_a","title":"this works ok","uid":3,"name":"rocksocker"}
This does not work and gives me a "Missing Required Arguments" message:
{"type":"type_a","title":"why doesnt this work","uid":3,"name":"rocksocker","field_custom_a": [{value:"test"}]}
And this generates a PHP error saying "Fatal error: Cannot use object of type stdClass as array in var/aegir/platforms/drupal6/sites/all/modules/cck/modules/text/text.module on line 439":
{"type":"type_a","title":"why doesnt this work","uid":3,"name":"rocksocker","field_custom_a": [{"value":"test"}]}
I believe this last example should work, according to examples I've found via Google.
Thank you
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | services-945788.patch | 971 bytes | kylebrowning |
| #11 | 945788_change_nodesave_arg_to_array.patch | 554 bytes | voxpelli |
Comments
Comment #1
HermosilloSoKRok commentedI improved title to attract a response, as it's got to be something simple that will save me hours.
Comment #2
HermosilloSoKRok commentedComment #3
marcingy commentedThis is a support request not a bug.
Comment #4
HermosilloSoKRok commentedYou are quite sure it is not a bug? Then you must understand the solution can you please share it with me?
Comment #5
HermosilloSoKRok commentedI am sorry but I feel I need to disagree. At least you can tell me your logic. I created a node in drupal and using node.get I can see the format required which is the same that is reporting the error.
Also I found this page which suggests the similar thing with user.save http://drupal.org/node/822090 and http://drupal.org/node/679494
Comment #6
HermosilloSoKRok commentedComment #7
HermosilloSoKRok commentedok I installed JSON Server because some other pages made me think the problem was the browser page. It took another few hours to figure out that because there seems to be a problem with documents and the code does not have any comments.
Only thanks to Google I have found some old pages that tell me I am doing the right thing:
cckfield = [{value:"this is the field text"}];
This throws errors on the JSON Server too so I am lead to decide that there is a problem within Services. I respect the person who says this is not a bug but he says this to me without saying any facts. For now I accept this is a support request but I have many doubts.
Comment #8
HermosilloSoKRok commentedThe error is "Fatal error: Cannot use object of type stdClass as array in var/aegir/platforms/drupal6/sites/all/modules/cck/modules/text/text.module on line 439" so I read that Services requires two arrays. No error is given when I do that but no data is saved when I use [[{value:"test"}]]
Again node.get provides the structure I try to use [{value:"test"}]. This is the thing that causes errors in node.save.
This is a bug!!
Comment #9
matteblacke commentedI am getting the same error for node.save using a similar string (below)
{"type":"rundata","uid":"1","title":"TITLE","body":"BODY","field_html_song_list":[{"value":"Song","format":"2"}]}
Cannot use object of type stdClass as array in modules/cck/modules/text/text.module on line 439
Comment #10
matteblacke commentedsorry, think i flicked the priority somehow.
Comment #11
voxpelli commentedThis is indeed a bug. The node resource is defined as a struct - but since it calls drupal_execute() all values sent to it should be arrays. Both the browser in Services itself and the JSON server decodes JSON into objects instead of into associative arrays.
Some services does some internal type casting to get around this but none of that casting is recursive so specifying an associative array as the value of a cck field will fail - since the cck field's form handler expects an array.
I would suggest that we remove the type 'struct' from Services 3.x and disallows objects in arguments - all complex values that Services will need to handle can be expressed as arrays. Would there be any drawbacks for doing this?
The fix for Services 2.2 would be to change the type of the node.save argument to be 'array'. Patch is attached for that.
A patch has also been sent to the JSON server: #952344: Check if argument is struct or array and parse differently
Comment #12
voxpelli commentedComment #14
kylebrowning commentedMaybe you meant to set this to dev so the patch works?
Comment #15
kylebrowning commented#11: 945788_change_nodesave_arg_to_array.patch queued for re-testing.
Comment #17
voxpelli commentedUm - how is it possible for such a small patch to fail? Can you try manually kylebrowning?
Comment #18
kylebrowning commentedRe-rolled patch.
Comment #19
kylebrowning commentedComment #20
gddThis is an API change, won't it break any existing installs?
Comment #21
marcingy commentedCan't comment on json but xmlrpc casts objects to arrays so xmlrpc has always been sending an array in effect anyway. So any xmlrpc code will still run as expected, other servers ???
Comment #22
voxpelli commented@heyrocker: The function accepting the argument hasn't changed and the argument types aren't enforced in any way.
The fact that argument types aren't enforced is the reason how this can have slipped through. The values sent to drupal_execute() emulates $_POST and $_POST is an array - not a struct.
JSON server doesn't check the type and has parsed everything as a struct - in #952344: Check if argument is struct or array and parse differently it will be changed.
The only place I know that actually checks the argument type is Services' own browser - and as reported in this and other issues it currently fails on CCK-data.
So: If any API-change has occurred then that has already been made, but it forgot to change the argument type.
And since, as marcingy notes, many servers actually doesn't differentiate between struct and array I really think that we should remove struct in favour of array: #954964: Remove argument type 'struct' in favor of 'array'
Comment #23
voxpelli commentedSeems like also neither the REST Server or the JSONRPC Server checks whether an argument is a struct or an array - they both always parse JSON as arrays.
Comment #24
marcingy commentedGiven voxpelli comments I'm happy to mark this rbtc as it sounds like no server is affected by the change as they already treat things as arrays anyway.
Comment #25
kylebrowning commentedThis has been commited to 2.x-dev
Comment #27
mayur.pimple commentedHi
This is poll type
-> how to update this node in services
[choice] => Array
(
[0] => Array
(
[chtext] => Football
[chvotes] => 2
[chorder] => 0
)
}
I want to update => [choice] [0] [chvotes] ;
Comment #28
voxpelli commented@mayurpimple: Open new issues - don't hijack old closed issues
Comment #29
newnewuser commentedsub